package com.huwei.kafka.controller;

import org.apache.kafka.common.protocol.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 胡伟
 * @Date: 2021/1/19 14:16
 * @Description:
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private KafkaTemplate kafkaTemplate;
    @GetMapping("sendMsg")
    public String sendMsg(@RequestParam("msg") String msg){
        //第一个参数为发送的主题，后面则是发送的消息
        kafkaTemplate.send("jiahong",msg);
        return "success";
    }
}
